
checkLogin();


var success = function (res) {
    var info = res.data;

    var html = template('address_detail',info);
    if(info.address_list == undefined || info.address_list== null || info.address_list == '' || info.address_list.length <=0){
        html = '<div class="no_data" style="background:#f1f1f1;align-content: center;height: ' + fenye_options.scrollHeight + ';padding-top: 50%;text-align: center;font-size: 20px;color: lightgray;">空空如也</div>';
    }
    $('#address_detail_content').append(html);

    //默认选中默认地址
    var list = info.address_list;
    if(list!=undefined && list!=null && list!='' && list.length>0){
        for(var i=0;i<list.length;i++){
            //表示当前为默认地址
            if(list[i].is_default == 1){
                $('.address').prop('checked',false);
                $('#address'+list[i].id).prop('checked', true);
                break;
            }
        }
    }

    //重选默认地址
    $('.address').on('tap',function () {
        var sPrents = $(this).parents(".mui-input-row");
        var detail = sPrents.attr('data');
        if(detail!=undefined && detail!=null&&detail!=''){
            detail = JSON.parse(detail);
            var id = detail.id;
            var name = detail.name;
            var mobile = detail.mobile;
            var address = detail.address;
            var area_info = detail.area_info;
            $('.address').prop('checked',false);
            $('#address'+address.id).prop('checked', true);

            postData(address_set_default,combineParams({id:id,name:name,mobile:mobile,address:address,area_info:area_info}));
        }
    })

    //点击编辑事件
    $('.edit').on('tap',function () {
        var sPrents = $(this).parents(".mui-input-row");
        var address = sPrents.attr('data');
        setCache(address_key,address);
        redirect('edit-address.html');
    })


   //绑定删除事件
    $('.delate').on('tap',function () {
        /*var id = parseInt(this.getAttribute('data'));*///获取当前项的data
        //获取上级项data
        var address_detail = $(this).parent().attr('data');
        address_detail = JSON.parse(address_detail);
        if(address_detail == undefined || address_detail == null || address_detail == ''){
            return;
        }
        var id = address_detail.id;
        var name = address_detail.name;
        var mobile = address_detail.mobile;
        var address = address_detail.address;
        var area_info = address_detail.area_info;
        mui.confirm('', '确认删除吗 ?', ['是', '否'], function (e) {
            if (e.index == 0) {
                var success = function (res) {
                    malert('删除成功',function (e) {
                        locationReplace("address.html");
                    });
                }
                postData(address_delete,combineParams({id:id,name:name,mobile:mobile,address:address,area_info:area_info}),success);
            }
        })
    })
}
getData(address_list,comParams(),success);

